﻿
Create proc [dbo].[proc_Customer_Track_GetList_New]
	(
		@CustomerId uniqueidentifier
	)
As

	WITH List As(Select ROW_NUMBER() OVER (Order By id Desc) AS Row,
	id,IntentionsId,-- PublicityDemandId,NetworkConsciousnessId,
	GenjinId,IsNull(Record,'') As Record,UpName,UpTime
	From Customer_Track
	Where CustomerId=@CustomerId
	)
	Select *,
	Case When UpName='' Then '...' Else	IsNull((Select Top 1 EName From Employee Where UserName=List.UpName),'...') End As EName,
	IsNull((Select Title From Customer_Intentions Where Id=List.IntentionsId),'...') As Intentions,
	IsNull((Select Title From Customer_Genjin Where Id=List.GenjinId),'...') As Genjin,
	(Select Count(0) From List) As RecordCount
	From List
	Where Row Between 1 And 5
	Order By Row